
export default class Index extends React.Component {
    constructor(props) {
        super(props);
     
        this.getValue = this.getValue.bind(this);
        this.inputRef = null;
        this.onBlur = this.onBlur.bind(this);
        this.onChange = this.onChange.bind(this);
    }
    getValue() {
        return this.inputRef["input"].value
    }
    onChange(e) {
        e.persist();
        let {reg,onChange} = this.props;
        if (reg) {
            let value = e.target.value;
            if (reg.test(value) || value === '') {
                onChange && onChange(value);
              }
        }
    }
  
    onBlur(e) {
        let {onBlur} = this.props;
        onBlur && onBlur(e);
    }
    render() {
        let {disabled,placeholder,value = "",className,maxLength} = this.props;
        return (
            <input
                ref={(c) => { this.inputRef = c }}
                className = {className}
                disabled={disabled}
                maxLength={maxLength}
                placeholder={placeholder}
                type="text"
                value={value}
                onBlur={this.onBlur}
                onChange={this.onChange.bind(this)}/>
        )
    }
}